<?php
if(!defined('IN_DISCUZ') || !defined('IN_ADMINCP')) {
    exit('Access Denied');
}

// 获取表模型
$table_er_kami = C::t('#erling_kami_buy#er_kami_buy');

if($_GET['action_kami_buy']){
    if($_GET['action_kami_buy'] == 'delete'){
        $table_er_kami->delete($_GET['action_kami_buy_id']);
    }
}

$url_page = ADMINSCRIPT.'?action=plugins&operation=config&do='.$pluginid.'&identifier=erling_kami_buy&pmod=admin_kami_buy_list';

// 获取当前列表
$page = max(1, intval($page));
$pagesize = max($_GET['pagesize']??20, intval($pagesize));
$start = ($page - 1) * $pagesize;

$expire_time = isset($_GET['expire_time']) ? strtotime($_GET['expire_time']) : TIMESTAMP;
$expire_date = ($expire_time != -1 && is_numeric($expire_time)) ? date('Y-m-d', $expire_time) : '';// 转换为日期格式

$query = [];
if(!empty($_GET['id'])){
    $query['id'] = intval($_GET['id']);
    $url_page .= '&id='.$_GET['id'];
}
if(!empty($_GET['uid'])){
    $query['uid'] = intval($_GET['uid']);
    $url_page .= '&uid='.$_GET['uid'];
}
if(!empty($_GET['status'])){
    $query['status'] = intval($_GET['status']);
    $url_page .= '&status='.$_GET['status'];
}
if(!empty($_GET['kami_key'])){
    $query['kami_key'] = trim($_GET['kami_key']);
    $url_page .= '&kami_key='.urlencode($_GET['kami_key']);
}
if(!empty($_GET['kami_type'])){
    $query['kami_type'] = intval($_GET['kami_type']);
    $url_page .= '&kami_type='.$_GET['kami_type'];
}
if(!empty($_GET['expire_time'])){
    $url_page .= '&expire_time='.$_GET['expire_time'];
}
$result = $table_er_kami->fetch_all($page, $pagesize, $query, $expire_time);
$kami_list = $result['data'];
$total = $result['total'];

if(!empty($_GET['pagesize'])){
    $url_page .= '&pagesize='.intval($_GET['pagesize']);
}
$multipage = multi($total, $pagesize, $page, $url_page);

// 获取分类
$table_er_kami_type = C::t('#erling_kami_buy#er_kami_buy_type')->fetch_all();
$kami_type_list = $table_er_kami_type['data'];


include template('erling_kami_buy:admin_kami_buy_list');
